import login from "@/api/login";
import { getToken, loginOut } from "@/utils/utils";
import { defineStore } from "pinia";

export const useUserStore = defineStore('user', {
	state: () => ({
		userInfo: <any>{},//用户信息
		isLogin: <boolean>getToken() && true,//是否登录
		LoginVisible: <boolean>false,//是否显示登录弹窗
		path:<any>{}//记录跳转路由信息
	}),
	getters: {

	},
	actions: {
		/**
		 * 获取用户信息
		 *
		 * @returns 返回Promise对象，该对象resolve时携带登录后用户的信息
		 */
		async getUserInfo() {
			this.isLogin = true
			const res = await login.AccountInfo_API()
			if (res.code === 0) {
				this.userInfo = res.data
			}
		},
		//退出登录
		clearLogin() {
			this.isLogin = false
			this.userInfo = {}
			loginOut()
		}
	},
	persist: true
})